package pro.cherish.knowledgedemovalid.config;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

@ControllerAdvice
@ResponseBody
public class GlobalException {


    @ExceptionHandler(java.lang.reflect.InvocationTargetException.class)
    public Object runtimeException(java.lang.reflect.InvocationTargetException e) {
        e.printStackTrace();
        HashMap<String, Object> map = new HashMap<>();
        map.put("status", 400);
        map.put("msg", e.getTargetException().getCause().getMessage());
        return map;
    }
    @ExceptionHandler(RuntimeException.class)
    public Object runtimeException(RuntimeException e) {
        e.printStackTrace();
        HashMap<String, Object> map = new HashMap<>();
        map.put("status",400);
        map.put("msg",e.getMessage());
        return map;
    }

}
